import  { useState } from 'react';
import { Upload, Button, Input } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import './index.css';

const FilePicker = ({onInputChange}) => {
  const [filePath, setFilePath] = useState('');

  const beforeUpload = (file) => {
    const isExe = file.type === 'application/x-msdownload'; // 判断文件类型是否为 exe
    if (!isExe) {
      console.error('You can only upload exe files!');
      return false; // 如果文件类型不是 exe，则阻止上传
    }
    setFilePath(file.path); // 设置文件路径
    onInputChange(file.path);
    console.log('file.Path:', file.path);
    console.log('FilePath:', filePath);
    return false; // 返回 false 阻止默认上传行为
  };

  return (
    <div className='container'>
      <Input className='input' value={filePath} placeholder='请输入目标程序路径' />
      <Upload
        className='select-btn'
        beforeUpload={beforeUpload}
        accept=".exe"
        showUploadList={false}
      >
        <Button icon={<UploadOutlined />}>选择目标程序</Button>
      </Upload>
    </div>
  );
};

export default FilePicker;
